<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var waysToMakeFair = function (nums, n = nums.length) {
      let cnt = 0, sum1 = 0, sum2 = 0
      for (let i = 1; i < n; i++) {
        if (i % 2 === 1) sum1 += nums[i]
        else sum2 += nums[i]
      }
      if (sum2 === sum1) cnt += 1
      for (let i = 1; i < n; i++) {
        if (i % 2 === 1) sum1 += nums[i - 1] - nums[i]
        else sum2 += nums[i - 1] - nums[i]
        if (sum1 === sum2) cnt += 1
      }
      return cnt
    };

    console.log(waysToMakeFair([1, 1, 1]))
  </script>
</body>

</html>